<?php
/**
 * 
 * ClientEngage: ClientEngage Visitor Voice (http://www.clientengage.com)
 * Copyright 2012, ClientEngage (http://www.clientengage.com)
 *
 * You must have purchased a valid license from CodeCanyon in order to have 
 * the permission to use this file.
 * 
 * You may only use this file according to the respective licensing terms 
 * you agreed to when purchasing this item on CodeCanyon.
 * 
 * 
 * 
 *
 * @author          ClientEngage <contact@clientengage.com>
 * @copyright       Copyright 2013, ClientEngage (http://www.clientengage.com)
 * @link            http://www.clientengage.com ClientEngage
 * @since           ClientEngage - Visitor Voice v 1.0
 * 
 */
?>
<?php
echo $this->Html->script('jquery/base64/jquery.base64.min');
$this->Html->scriptBlock('
$(function(){
    $(".check_required").click(function(){
        if($(this).is(":checked"))
            $(".required_message").fadeIn();
        else
            $(".required_message").fadeOut();
    });
    if(!$(".check_required").is(":checked"))
        $(".required_message").hide();
        

    $(".input_regex").keyup(function(){
        if($(this).val().trim() != "")
            $(".regex_message").fadeIn();
        else
            $(".regex_message").fadeOut();
    });
    if($(".input_regex").length > 0 && $(".input_regex").val().trim() == "")
        $(".regex_message").hide();
        
    $(".select_regex").change(function(){
        $(".input_regex").val($.base64.decode($(this).val()));
        $(this).val("default");
        $(".regex_message").fadeIn();
    });
});    
', array('inline' => false));
?>
<div class="row-fluid">
    <div class="<?php echo in_array($field['Field']['type'], array('htmlspacer', 'submit', 'captcha')) ? 'span12' : 'span6'; ?>">
        <h3><?php echo __('Settings'); ?></h3>
        <?php
        if ($isAddField)
        {
            echo $this->Form->input('type', array('type' => 'hidden'));
            echo $this->Form->input('visitorform_id', array('type' => 'hidden'));
        }
        else
        {
            echo $this->Form->input('id');
            echo $this->Form->input('type', array('type' => 'hidden', 'value' => $field['Field']['type']));
        }
        echo $this->Form->input('title', array('label' => __('Title')));

        if ($field['Field']['type'] != 'submit')
            echo $this->Form->tinyMce('description', array('label' => __('Description')));

        if (in_array($field['Field']['type'], array('textshort', 'textlong', 'spinner', 'date', 'select', 'radio', 'selectmultiple', 'checkboxmultiple', 'checkbox', 'captcha', 'submit')))
        {
            echo $this->Form->input('class_suffix_input', array('label' => __('Input CSS-Class Suffix')));
        }
        if ($field['Field']['type'] != 'htmlspacer')
            echo $this->Form->input('class_suffix_container', array('label' => __('Container CSS-Class Suffix')));

        if (in_array($field['Field']['type'], array('textshort', 'textlong', 'spinner', 'date')))
            echo $this->Form->input('placeholder', array('label' => __('Placeholder Text')));

        if (in_array($field['Field']['type'], array('rating', 'slider', 'spinner')))
        {
            if ($field['Field']['type'] != 'rating')
                echo $this->Form->input('custom_min', array('label' => __('Minimum Value')));
            echo $this->Form->input('custom_max', array('label' => __('Maximum Value')));
        }
        ?>
    </div>  

    <?php if (!in_array($field['Field']['type'], array('htmlspacer', 'submit'))): ?>
        <div class="span6">
            <h3><?php echo __('Validation'); ?></h3>
            <?php
            echo $this->Form->input('required', array('class' => 'check_required', 'label' => __('Required')));
            echo $this->Form->input('required_message', array('div' => 'input text required_message', 'label' => __('Required Message')));


            if (!in_array($field['Field']['type'], array('select', 'radio', 'checkbox', 'captcha', 'selectmultiple', 'checkboxmultiple', 'slider', 'rating', 'spinner', 'date')))
            {
                echo $this->Form->input('Selector.regex_selector', array('label' => __('RegEx Template Selection'), 'type' => 'select', 'class' => 'select_regex', 'options' => array('default' => __('Select Validation Rule')) + $validationRules));
                echo $this->Form->input('validation_regex', array('class' => 'input_regex span12', 'label' => __('Validation RegEx')));
                echo $this->Form->input('validation_message', array('div' => 'input textarea regex_message', 'label' => __('Validation Error Message')));
            }
            ?>

        </div>  
    <?php endif; ?>
    <?php if (!$isAddField && in_array($field['Field']['type'], array('select', 'radio', 'selectmultiple', 'checkboxmultiple'))): ?>
        <div class="row-fluid">
            <div class="span12">
                <hr />
                <h3><?php echo __('Available Options'); ?></h3>
                <?php
                $i = 0;
                foreach ($field['FieldOption'] as $opt):
                    ?>
                    <div class="row-fluid">
                        <div class="span2">
                            <?php
                            echo $this->Html->link('<i class="ico-bullet_arrow_up"></i>', array('controller' => 'field_options', 'action' => 'moveup', $opt['id']), array('class' => 'bftn btfn-mini', 'escape' => false));
                            echo $this->Html->link('<i class="ico-bullet_arrow_down"></i>', array('controller' => 'field_options', 'action' => 'movedown', $opt['id']), array('class' => 'btnf bftn-mini', 'escape' => false)) . '<br />';
                            ?>
                        </div>
                        <div class="span10">
                            <?php
                            echo $this->Form->input('FieldOption.' . $i . '.title', array('label' => false, 'value' => $opt['title'], 'div' => 'input-append span12', 'class' => 'span11', 'after' => $this->Html->link('<i class="ico-cancel"></i>', array('controller' => 'field_options', 'action' => 'delete', $opt['id']), array('class' => 'btn btn-danger', 'escape' => false))));
                            echo $this->Form->input('FieldOption.' . $i . '.id', array('value' => $opt['id']));
                            $i++;
                            ?>
                        </div>

                    </div>
                <?php endforeach; ?>        
                <div class="row-fluid">
                    <div class="span2">
                        &nbsp;
                        <?php
                        ?>
                    </div>
                    <div class="span10">
                        <?php
                        echo $this->Form->input('FieldOption.' . $i . '.title', array('label' => false, 'placeholder' => __('Enter a new option')));
                        ?>
                    </div>
                </div>
            </div>
        </div> 
    <?php endif; ?>

</div>



